/*
* Copyright (c) 2011 Connection Road.  All rights reserved.
* This program and the accompanying material are made available
* under the terms of the Eclipse Public Licnese v1.0 which is
* available at http://www.eclipse.org/legal/epl-v10.html
*/

using System.Drawing;
using System.Windows.Forms;

namespace CrSyncFilesForms.Forms
{
    public partial class CRSyncShapeOval : UserControl
    {
        private Graphics DefaultShape { get; set; }
        private Pen DefaultPen { get; set; }
        public Color ShapeFillColor { get; set; }
        public Color ShapeForeColor { get; set; }
        public int ShapeWidth { get; set; }

        public CRSyncShapeOval()
        {
            InitializeComponent();
        }

        public void Init(Rectangle rect)
        {
            Brush fillColor;
            using(fillColor = new SolidBrush(ShapeFillColor)){
                ShapeWidth = (ShapeWidth == 0) ? 1 : ShapeWidth;
                DefaultPen = new Pen(ShapeForeColor, ShapeWidth);
                DefaultShape = CreateGraphics();
                DefaultShape.FillEllipse(fillColor, rect);
            }
        }

        private void DefaultOnPaint(object sender, PaintEventArgs e)
        {
           var rect = e.ClipRectangle;
           var newRect = new Rectangle(rect.X, rect.Y, rect.Width - 3, rect.Height - 3);
           Init(newRect);
        }
    }
}
